<?php
//2011-12-08
require( "../classes/mofachi.User.php" );
require( "../classes/mofachi.Location.php" );
$user = new User();
@ $user->user_id = $_POST[ "uid" ];
@ $user->nickname = $_POST[ "nn" ];
@ $user->realname = $_POST[ "rn" ];
@ $user->gender = $_POST[ "gd" ];
@ $user->birthday = $_POST[ "br" ];

@ $region_code = $_POST[ "urc" ];
@ $city_code = $_POST[ "ucc" ];

header( 'Content-Type: text/plain; charset=utf-8' );
if( !$user->user_id || !$user->nickname ){
	echo utf8_encode( "{\"reply\":-1,\"msg\":\"ERROR: No user id or nickname\"}" );
	exit();
}
$user->loadInfoByNickname();
if( $user->isLoaded() ) {
	echo utf8_encode( "{\"reply\":0,\"msg\":\"ERROR: The nickname has been used\"}" );
	exit();
}
$user->location_id = "";
if( $city_code ) {
	$loc = new Location();
	$loc->city_code = $city_code;
	if( $loc->loadByCityCode() )
		$user->location_id = $loc->location_id;
} else if( $region_code ) {
	$loc = new Location();
	$loc->region_code = $region_code;
	if( $loc->loadByRegionCode() )
		$user->location_id = $loc->location_id;
}
if( $user->addInfo() ) {
	echo utf8_encode( "{\"reply\":".$user->user_id.",\"msg\":\"Success: The user information has been added!\"}" );
}
?>